package com.ceair.mub2c.payment.payments.utils;

import java.io.File;

public class StringUtils {
	
	/**
	 * Gets the root path of server.
	 * 
	 * @return the root path
	 */
	public static String getRootPath() {
		String classPath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
		String rootPath = "";

		/** For Windows */
		if ("\\".equals(File.separator)) {
			if (classPath.indexOf("/WEB-INF/classes") != -1) {
				rootPath = classPath.substring(1, classPath.indexOf("/WEB-INF/classes"));
			} else if (classPath.indexOf("/target/classes") != -1) {
				rootPath = classPath.substring(1, classPath.indexOf("/target/classes"));
			}
			if (rootPath.lastIndexOf("/") > 0) {
				rootPath = rootPath.substring(0, rootPath.lastIndexOf("/"));
			}
			rootPath = rootPath.replace("/", "\\");
		}

		/** For Linux */
		if ("/".equals(File.separator)) {
			if (classPath.indexOf("/WEB-INF/classes") != -1) {
				rootPath = classPath.substring(0, classPath.indexOf("/WEB-INF/classes"));
			} else if (classPath.indexOf("/target/classes") != -1) {
				rootPath = classPath.substring(0, classPath.indexOf("/target/classes"));
			}
			if (rootPath.lastIndexOf("/") > 0) {
				rootPath = rootPath.substring(0, rootPath.lastIndexOf("/"));
			}
			rootPath = rootPath.replace("\\", "/");
		}
		return rootPath;
	}
	
}
